#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void sdvig(int a[],int t, int n)
{
	int i;
	for(i=t+1;i<(n+1);i++)
		a[i-1]=a[i];
}

void main()

{
	int i,p,r,a[100000];
	int n,k;

	printf("Enter n and d\n");
	scanf("%d", &n,"\n");
	scanf("%d", &k,"\n");
	printf("\n");

	for(i=1;i<n+1;i++)
		a[i]=i;
	p=n;
	r=k;
	for(i=0;i<n;i++)
	{
		if((r>p) & (r%p != 0))
			r=r%p;
		if(r%p == 0)
			r=p;
		if(p==1) 
			break;

		
		printf("%d\n", a[r]);
		if((p-r-1)>0)
		memmove(&a[r],&a[r+1],(p-r-1)*sizeof(int));
		//sdvig(a,r,p);
		p--;
		r=r+k-1;
	}

	printf("\n %d is win\n", a[1]); 

	system("PAUSE");
}